/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_drjs/main", [
            "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
            "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
            "../../plugins/artTemplate/artTemplate",
            "../../common/tools",
            "../../common/componts",
            "../../pages/jls_drjs/form",
            "../../pages/jls_drjs/DrjsShowHide.html.js",
        ],
        function(require) {
            var comonts=require("../../common/componts");
            var DrjsForm=require("../../pages/jls_drjs/form");
            var tmp=require("../../pages/jls_drjs/DrjsShowHide.html");
            var drjsId="drjsId";
            var selectid;
            var top="30px";
            var drjs='drjs';
            var initTable=function(){
                comonts.initTable(drjsId,{
                    title: '带入拘室',
                    url:"/jls_drjs/drjsList",
                    toolbar:'#tool',
                    firstLoad:true,
                    pageSize: 20,
                    columns:[
                        {field: 'oid',title: '',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="drjsIdRadio" id="drjsIdRadio"' + rowIndex + 'value="' + rowData.oid + '" />';}},
                        /*{
                            field : 'id',
                            width : 150,
                            title:'id',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.id == null ? "" : row.id)+'</span>'
                            }},*/
                        {
                            field : 'rybh',
                            width : 150,
                            title:'人员编号',
                            sortable:'false',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.rybh == null ? "" : row.rybh)+'</span>'
                            }},
                        {
                            field : 'name',
                            width : 150,
                            title:'姓名',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.name == null ? "" : row.name)+'</span>'
                            }},
                        {
                            field : 'jsh',
                            width : 150,
                            title:'拘室号',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.jsh == null ? "" : row.jsh)+'</span>'
                            }},
                        {
                            field : 'rsrq',
                            width : 150,
                            title:'入所日期',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.rsrq == null ? "" : row.rsrq)+'</span>'
                            }},
                        {
                            field : 'rjyy',
                            width : 150,
                            title:'入拘原因',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.rjyy == null ? "" : row.rjyy)+'</span>'
                            }},
                        {
                            field : 'wfxw',
                            width : 150,
                            title:'违法行为',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.wfxw== null ? "" : row.wfxw)+'</span>'
                            }},

                        ],
                    detailFormatter:function(index,rowData){
                        return '<table style="height:40px;width:100%"><tr><td><strong></strong></td></tr></table>'
                    },
                    onClickRow:function(rowIndex, rowData){
                        if (selectid != rowData.id) {
                            $("input[name='drjsIdRadio']")[rowIndex].checked = true;
                            $('#' + drjsId).datagrid("selectRow", rowIndex);
                            selectid = rowData.id;
                        } else if (selectid == rowData.id) {
                            $('#' + drjsId).datagrid("unselectRow", rowIndex);
                            $("input[name='drjsIdRadio']")[rowIndex].checked = false;
                            selectid = "";
                        }
                    },
                });
                $('#drjsId').datagrid('resize', {
                    height: ($(window).height()-35 )
                });
            }
            var findDrjs=function(){
                var opts = $('#'+drjsId).datagrid("options");
                opts.url = "/jls_jbxx/jbxxList";
                $('#'+drjsId).datagrid('clearSelections');
                $('#'+drjsId).datagrid('load',{
                });
            }
            var bindAction=function(){
                //查询
                $("#drjs_search").on("click",function(){
                    findDrjs();
                });
                //新增
                $("#drjs_add").on("click",function(){
                    var Drjs=$("#"+drjsId).datagrid('getSelected');
                    if(Drjs){
                        DrjsForm.show(findDrjs,Drjs);
                    }else{
                        $.messager.alert("提示","请先选择要办理的人!","info");
                    }
                });
                //修改
                $("#drjs_update").on("click",function(){
                    var Drjs=$("#"+drjsId).datagrid('getSelected');
                    if(Drjs){
                        DrjsForm.show(findDrjs,Drjs);
                    }else{
                        $.messager.alert("提示","请选择要修改的记录!","info");
                    }
                });
                //删除
                $("#drjs_remove").on("click",function(){
                    //把你选中的 数据查询出来。
                    var selectRows = $('#drjsId').datagrid("getSelections");
                    if(selectRows==null||selectRows==undefined){

                        return  $.messager.alert("提示消息", "请选中要删的数据!");
                    }else{
                        $.messager.confirm("操作提示", "您确定要删除该条记录吗？", function (data) {

                            if(data) {
                                submitLoad();
                                $.ajax({
                                    type : "POST",  //提交方式
                                    url : "/jls_drjs/drjsDelete",//路径
                                    data : {id:selectRows[0].id},//数据，这里使用的是Json格式进行传输
                                    success : function(result) {
                                        if (result.success) {
                                            $.messager.alert("确定","删除成功","info");
                                            findDrjs();
                                        }else{
                                            removeLoad();
                                            $.messager.alert("确定","删除失败","info");
                                        }
                                    },
                                    complete:function(){
                                        removeLoad();
                                    },
                                });
                            }else {
                                return false;
                            }

                        });

                    }
                });
                comonts.ShowHide(drjs,tmp);
            }
            var initView=function(){
                initTable();
                bindAction();
            }
            initView();

        });